package com.dbqn.zhao.service.impl;

import com.dbqn.zhao.entiy.User;
import com.dbqn.zhao.service.BaseService;

import java.util.List;
import java.util.Scanner;

public class UpdateImpl implements BaseService {

    Scanner sc=new Scanner(System.in);

    @Override
    public List excute(List list) {

        System.out.println("*****修改订单******");
        System.out.println("请输入您要修改的单号:");
        String danh=sc.next();

        User jies= panduna(danh,list);//判断单号是否存在



        if(jies!=null){

            if(jies.getCount()>0){
                System.out.println("修改次数用完！不能修改！");
                return null;
            }
            for(;;){
                System.out.println("请输入新的收件人信息:");
                String recipients=sc.next();
                if(recipients.trim().isEmpty()){
                    System.out.println("取件人信息不能为空！");
                }else{
                    jies.setRecipients(recipients );
                    jies.setCount(1);
                    System.out.println("修改成功！");
                    System.out.println("*****更新后的订单为******");
                    System.out.println("快递单号:"+jies.getDanh());
                    System.out.println("收件人信息:"+jies.getRecipients());
                    break;
                }

            }

        }else {

            System.out.println("该单号不存在！");
        }

        return null;
    }


   public User panduna(String s,List list){

       for (int i = 0; i < list.size(); i++) {

           User user=(User)list.get(i);
           if( s.equals(user.getDanh())){
               return user;
           }

       }

        return null;

   }


}
